Imports cmplib01

Public Class frmDeployUnit
    Inherits System.Windows.Forms.Form

    Private ptrCurrentGame As CampaignerGameData
    Private ptrNewUnit As GroundChitType
    Private ptrDeploymentZone As DeploymentZone
    Private bunitSelected As Boolean = False
    Private selectedUnitType As UnitType

    Private m_ActionCancelled As Boolean

    Public ReadOnly Property SelectedUnit() As UnitType
        Get
            Return selectedUnitType
        End Get
    End Property


#Region " Windows Form Designer generated code "

    Private Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents pnlTopBorder As System.Windows.Forms.Panel
    Friend WithEvents picCampaignerIcon As System.Windows.Forms.PictureBox
    Friend WithEvents txtTitleBox As System.Windows.Forms.TextBox
    Friend WithEvents pnlFactionOneProperties As System.Windows.Forms.Panel
    Friend WithEvents lblFactionOneDeployedPoints As System.Windows.Forms.Label
    Friend WithEvents txtPointValue As System.Windows.Forms.TextBox
    Friend WithEvents lblChitName As System.Windows.Forms.Label
    Friend WithEvents txtChitName As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents imlUnitIcons As System.Windows.Forms.ImageList
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents txtAvailablePoints As System.Windows.Forms.TextBox
    Friend WithEvents txtSelectedUnitDescription As System.Windows.Forms.TextBox
    Friend WithEvents tvwUnitTypes As System.Windows.Forms.TreeView
    Friend WithEvents lblPVThisTurn As System.Windows.Forms.Label
    Friend WithEvents txtPVAvailableThisTurn As System.Windows.Forms.TextBox
    Friend WithEvents lblDeploymentPV As System.Windows.Forms.Label
    Friend WithEvents txtDeploymentZonePV As System.Windows.Forms.TextBox
    Friend WithEvents lblZoneName As System.Windows.Forms.Label
    Friend WithEvents txtZoneName As System.Windows.Forms.TextBox
    Friend WithEvents lvwElements As System.Windows.Forms.ListView
    Friend WithEvents colCount As System.Windows.Forms.ColumnHeader
    Friend WithEvents colElementName As System.Windows.Forms.ColumnHeader
    Friend WithEvents btnElements As System.Windows.Forms.Button
    Friend WithEvents chkUseElementsForPointValue As System.Windows.Forms.CheckBox
    Friend WithEvents lblSelectUnitType As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.btnOK = New System.Windows.Forms.Button()
        Me.pnlTopBorder = New System.Windows.Forms.Panel()
        Me.picCampaignerIcon = New System.Windows.Forms.PictureBox()
        Me.txtTitleBox = New System.Windows.Forms.TextBox()
        Me.pnlFactionOneProperties = New System.Windows.Forms.Panel()
        Me.chkUseElementsForPointValue = New System.Windows.Forms.CheckBox()
        Me.btnElements = New System.Windows.Forms.Button()
        Me.lblZoneName = New System.Windows.Forms.Label()
        Me.txtZoneName = New System.Windows.Forms.TextBox()
        Me.lblPVThisTurn = New System.Windows.Forms.Label()
        Me.txtPVAvailableThisTurn = New System.Windows.Forms.TextBox()
        Me.lblDeploymentPV = New System.Windows.Forms.Label()
        Me.txtDeploymentZonePV = New System.Windows.Forms.TextBox()
        Me.tvwUnitTypes = New System.Windows.Forms.TreeView()
        Me.imlUnitIcons = New System.Windows.Forms.ImageList(Me.components)
        Me.Label1 = New System.Windows.Forms.Label()
        Me.txtAvailablePoints = New System.Windows.Forms.TextBox()
        Me.lblFactionOneDeployedPoints = New System.Windows.Forms.Label()
        Me.txtPointValue = New System.Windows.Forms.TextBox()
        Me.lblChitName = New System.Windows.Forms.Label()
        Me.txtChitName = New System.Windows.Forms.TextBox()
        Me.lvwElements = New System.Windows.Forms.ListView()
        Me.colCount = New System.Windows.Forms.ColumnHeader()
        Me.colElementName = New System.Windows.Forms.ColumnHeader()
        Me.txtSelectedUnitDescription = New System.Windows.Forms.TextBox()
        Me.btnCancel = New System.Windows.Forms.Button()
        Me.lblSelectUnitType = New System.Windows.Forms.Label()
        Me.pnlTopBorder.SuspendLayout()
        Me.pnlFactionOneProperties.SuspendLayout()
        Me.SuspendLayout()
        '
        'btnOK
        '
        Me.btnOK.BackColor = System.Drawing.Color.LightSkyBlue
        Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOK.Location = New System.Drawing.Point(312, 397)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.TabIndex = 20
        Me.btnOK.Text = "OK"
        '
        'pnlTopBorder
        '
        Me.pnlTopBorder.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.pnlTopBorder.BackColor = System.Drawing.Color.SteelBlue
        Me.pnlTopBorder.Controls.AddRange(New System.Windows.Forms.Control() {Me.picCampaignerIcon, Me.txtTitleBox})
        Me.pnlTopBorder.Name = "pnlTopBorder"
        Me.pnlTopBorder.Size = New System.Drawing.Size(482, 40)
        Me.pnlTopBorder.TabIndex = 19
        '
        'picCampaignerIcon
        '
        Me.picCampaignerIcon.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picCampaignerIcon.Location = New System.Drawing.Point(6, 3)
        Me.picCampaignerIcon.Name = "picCampaignerIcon"
        Me.picCampaignerIcon.Size = New System.Drawing.Size(32, 32)
        Me.picCampaignerIcon.TabIndex = 9
        Me.picCampaignerIcon.TabStop = False
        '
        'txtTitleBox
        '
        Me.txtTitleBox.BackColor = System.Drawing.Color.SteelBlue
        Me.txtTitleBox.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.txtTitleBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtTitleBox.ForeColor = System.Drawing.Color.WhiteSmoke
        Me.txtTitleBox.Location = New System.Drawing.Point(48, 8)
        Me.txtTitleBox.Multiline = True
        Me.txtTitleBox.Name = "txtTitleBox"
        Me.txtTitleBox.ReadOnly = True
        Me.txtTitleBox.Size = New System.Drawing.Size(176, 26)
        Me.txtTitleBox.TabIndex = 8
        Me.txtTitleBox.Text = "DeployChit"
        '
        'pnlFactionOneProperties
        '
        Me.pnlFactionOneProperties.BackColor = System.Drawing.Color.LightSkyBlue
        Me.pnlFactionOneProperties.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlFactionOneProperties.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblSelectUnitType, Me.chkUseElementsForPointValue, Me.btnElements, Me.lblZoneName, Me.txtZoneName, Me.lblPVThisTurn, Me.txtPVAvailableThisTurn, Me.lblDeploymentPV, Me.txtDeploymentZonePV, Me.tvwUnitTypes, Me.Label1, Me.txtAvailablePoints, Me.lblFactionOneDeployedPoints, Me.txtPointValue, Me.lblChitName, Me.txtChitName, Me.lvwElements, Me.txtSelectedUnitDescription})
        Me.pnlFactionOneProperties.Location = New System.Drawing.Point(8, 48)
        Me.pnlFactionOneProperties.Name = "pnlFactionOneProperties"
        Me.pnlFactionOneProperties.Size = New System.Drawing.Size(464, 344)
        Me.pnlFactionOneProperties.TabIndex = 18
        '
        'chkUseElementsForPointValue
        '
        Me.chkUseElementsForPointValue.CheckAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.chkUseElementsForPointValue.Location = New System.Drawing.Point(16, 316)
        Me.chkUseElementsForPointValue.Name = "chkUseElementsForPointValue"
        Me.chkUseElementsForPointValue.Size = New System.Drawing.Size(120, 16)
        Me.chkUseElementsForPointValue.TabIndex = 22
        Me.chkUseElementsForPointValue.Text = "Use Elements PV"
        '
        'btnElements
        '
        Me.btnElements.BackColor = System.Drawing.Color.LightBlue
        Me.btnElements.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnElements.Location = New System.Drawing.Point(152, 312)
        Me.btnElements.Name = "btnElements"
        Me.btnElements.TabIndex = 21
        Me.btnElements.Text = "Elements"
        '
        'lblZoneName
        '
        Me.lblZoneName.Location = New System.Drawing.Point(15, 96)
        Me.lblZoneName.Name = "lblZoneName"
        Me.lblZoneName.Size = New System.Drawing.Size(97, 16)
        Me.lblZoneName.TabIndex = 17
        Me.lblZoneName.Text = "Zone Name"
        '
        'txtZoneName
        '
        Me.txtZoneName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtZoneName.Location = New System.Drawing.Point(119, 96)
        Me.txtZoneName.Name = "txtZoneName"
        Me.txtZoneName.ReadOnly = True
        Me.txtZoneName.Size = New System.Drawing.Size(112, 21)
        Me.txtZoneName.TabIndex = 16
        Me.txtZoneName.Text = "Some Name"
        '
        'lblPVThisTurn
        '
        Me.lblPVThisTurn.Location = New System.Drawing.Point(15, 160)
        Me.lblPVThisTurn.Name = "lblPVThisTurn"
        Me.lblPVThisTurn.Size = New System.Drawing.Size(97, 16)
        Me.lblPVThisTurn.TabIndex = 15
        Me.lblPVThisTurn.Text = "PV This Turn"
        '
        'txtPVAvailableThisTurn
        '
        Me.txtPVAvailableThisTurn.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtPVAvailableThisTurn.Location = New System.Drawing.Point(119, 160)
        Me.txtPVAvailableThisTurn.Name = "txtPVAvailableThisTurn"
        Me.txtPVAvailableThisTurn.ReadOnly = True
        Me.txtPVAvailableThisTurn.Size = New System.Drawing.Size(112, 21)
        Me.txtPVAvailableThisTurn.TabIndex = 14
        Me.txtPVAvailableThisTurn.Text = "0"
        Me.txtPVAvailableThisTurn.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'lblDeploymentPV
        '
        Me.lblDeploymentPV.Location = New System.Drawing.Point(15, 128)
        Me.lblDeploymentPV.Name = "lblDeploymentPV"
        Me.lblDeploymentPV.Size = New System.Drawing.Size(97, 16)
        Me.lblDeploymentPV.TabIndex = 13
        Me.lblDeploymentPV.Text = "Deployment PV"
        '
        'txtDeploymentZonePV
        '
        Me.txtDeploymentZonePV.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtDeploymentZonePV.Location = New System.Drawing.Point(119, 128)
        Me.txtDeploymentZonePV.Name = "txtDeploymentZonePV"
        Me.txtDeploymentZonePV.ReadOnly = True
        Me.txtDeploymentZonePV.Size = New System.Drawing.Size(112, 21)
        Me.txtDeploymentZonePV.TabIndex = 12
        Me.txtDeploymentZonePV.Text = "0"
        Me.txtDeploymentZonePV.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'tvwUnitTypes
        '
        Me.tvwUnitTypes.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tvwUnitTypes.ImageList = Me.imlUnitIcons
        Me.tvwUnitTypes.Location = New System.Drawing.Point(240, 64)
        Me.tvwUnitTypes.Name = "tvwUnitTypes"
        Me.tvwUnitTypes.ShowLines = False
        Me.tvwUnitTypes.ShowPlusMinus = False
        Me.tvwUnitTypes.ShowRootLines = False
        Me.tvwUnitTypes.Size = New System.Drawing.Size(216, 152)
        Me.tvwUnitTypes.TabIndex = 11
        '
        'imlUnitIcons
        '
        Me.imlUnitIcons.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit
        Me.imlUnitIcons.ImageSize = New System.Drawing.Size(16, 16)
        Me.imlUnitIcons.TransparentColor = System.Drawing.Color.Transparent
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(15, 67)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(97, 16)
        Me.Label1.TabIndex = 8
        Me.Label1.Text = "Faction PV"
        '
        'txtAvailablePoints
        '
        Me.txtAvailablePoints.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtAvailablePoints.Location = New System.Drawing.Point(119, 64)
        Me.txtAvailablePoints.Name = "txtAvailablePoints"
        Me.txtAvailablePoints.ReadOnly = True
        Me.txtAvailablePoints.Size = New System.Drawing.Size(112, 21)
        Me.txtAvailablePoints.TabIndex = 7
        Me.txtAvailablePoints.Text = "0"
        Me.txtAvailablePoints.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'lblFactionOneDeployedPoints
        '
        Me.lblFactionOneDeployedPoints.Location = New System.Drawing.Point(16, 192)
        Me.lblFactionOneDeployedPoints.Name = "lblFactionOneDeployedPoints"
        Me.lblFactionOneDeployedPoints.Size = New System.Drawing.Size(97, 16)
        Me.lblFactionOneDeployedPoints.TabIndex = 6
        Me.lblFactionOneDeployedPoints.Text = "Unit Point Value"
        '
        'txtPointValue
        '
        Me.txtPointValue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtPointValue.Location = New System.Drawing.Point(120, 192)
        Me.txtPointValue.Name = "txtPointValue"
        Me.txtPointValue.Size = New System.Drawing.Size(112, 21)
        Me.txtPointValue.TabIndex = 5
        Me.txtPointValue.Text = "0"
        Me.txtPointValue.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'lblChitName
        '
        Me.lblChitName.Location = New System.Drawing.Point(16, 8)
        Me.lblChitName.Name = "lblChitName"
        Me.lblChitName.Size = New System.Drawing.Size(168, 24)
        Me.lblChitName.TabIndex = 3
        Me.lblChitName.Text = "Chit Name"
        '
        'txtChitName
        '
        Me.txtChitName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtChitName.Location = New System.Drawing.Point(16, 32)
        Me.txtChitName.Name = "txtChitName"
        Me.txtChitName.Size = New System.Drawing.Size(216, 21)
        Me.txtChitName.TabIndex = 0
        Me.txtChitName.Text = "Enter a name"
        '
        'lvwElements
        '
        Me.lvwElements.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lvwElements.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.colCount, Me.colElementName})
        Me.lvwElements.GridLines = True
        Me.lvwElements.Location = New System.Drawing.Point(16, 224)
        Me.lvwElements.Name = "lvwElements"
        Me.lvwElements.Size = New System.Drawing.Size(216, 83)
        Me.lvwElements.TabIndex = 12
        Me.lvwElements.View = System.Windows.Forms.View.Details
        '
        'colCount
        '
        Me.colCount.Text = "Count"
        Me.colCount.Width = 44
        '
        'colElementName
        '
        Me.colElementName.Text = "Element Name"
        Me.colElementName.Width = 152
        '
        'txtSelectedUnitDescription
        '
        Me.txtSelectedUnitDescription.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtSelectedUnitDescription.Location = New System.Drawing.Point(240, 224)
        Me.txtSelectedUnitDescription.Multiline = True
        Me.txtSelectedUnitDescription.Name = "txtSelectedUnitDescription"
        Me.txtSelectedUnitDescription.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.txtSelectedUnitDescription.Size = New System.Drawing.Size(216, 83)
        Me.txtSelectedUnitDescription.TabIndex = 10
        Me.txtSelectedUnitDescription.Text = "<No Unit Selected>"
        '
        'btnCancel
        '
        Me.btnCancel.BackColor = System.Drawing.Color.LightSkyBlue
        Me.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnCancel.Location = New System.Drawing.Point(392, 397)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.TabIndex = 21
        Me.btnCancel.Text = "Cancel"
        '
        'lblSelectUnitType
        '
        Me.lblSelectUnitType.Location = New System.Drawing.Point(240, 40)
        Me.lblSelectUnitType.Name = "lblSelectUnitType"
        Me.lblSelectUnitType.Size = New System.Drawing.Size(104, 16)
        Me.lblSelectUnitType.TabIndex = 23
        Me.lblSelectUnitType.Text = "Select Unit Type"
        '
        'frmDeployUnit
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.Color.Black
        Me.ClientSize = New System.Drawing.Size(482, 424)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnCancel, Me.btnOK, Me.pnlTopBorder, Me.pnlFactionOneProperties})
        Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.Name = "frmDeployUnit"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.pnlTopBorder.ResumeLayout(False)
        Me.pnlFactionOneProperties.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Sub New(ByRef GameData As CampaignerGameData, ByRef NewUnit As GroundChitType, ByRef depZone As DeploymentZone)
        Me.New()

        ptrCurrentGame = GameData
        ptrNewUnit = NewUnit

        ' populate the imagelist and units list with the units available
        PopulateUnitsList()
        ptrDeploymentZone = depZone
        ' if there are no points remaining for this turn, return false
        ShowAvailablePoints()


    End Sub

    Private Sub PopulateUnitsList()
        Dim key As String
        Dim unit As UnitType
        Dim index As Int16

        For Each key In ptrCurrentGame.UnitTypes.Keys
            unit = ptrCurrentGame.UnitTypes.Item(key)
            ' add the unit's icon to the imagelist
            imlUnitIcons.Images.Add(unit.Icon(cmplib01.IconImageIndex_cgd.Owner))
            Dim nodUnit As New TreeNode()
            nodUnit.Text = unit.TypeName
            nodUnit.Tag = unit.Key
            nodUnit.ImageIndex = index
            nodUnit.SelectedImageIndex = index
            tvwUnitTypes.Nodes.Add(nodUnit)
            index += 1
        Next

    End Sub

    Private Sub tvwUnitTypes_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwUnitTypes.AfterSelect
        Dim selNode As TreeNode = e.Node
        Dim unit As UnitType = ptrCurrentGame.UnitTypes.Item(selNode.Tag)

        txtSelectedUnitDescription.Text = unit.Description

        ' set up the selected unit
        selectedUnitType = unit
        bunitSelected = True

    End Sub

    Private Function ShowAvailablePoints() As Boolean
        Dim fact As cmplib01.Faction
        fact = ptrCurrentGame.Faction_g.Item(ptrCurrentGame.selectedPlayer.FactionKey)
        txtAvailablePoints.Text = fact.FactionFreePoints
        txtZoneName.Text = ptrDeploymentZone.ZoneName
        txtDeploymentZonePV.Text = ptrDeploymentZone.MaxTotalDeploy
        txtPVAvailableThisTurn.Text = ptrDeploymentZone.MaxDeploymentPerTurn - ptrDeploymentZone.PointsDeployedThisTurn
        ' if the amount available is less than the amount per turn, then the amount per turn = remaining points for this deployment zone
        If CInt(txtPVAvailableThisTurn.Text) > CInt(txtAvailablePoints.Text) Then txtPVAvailableThisTurn.Text = txtAvailablePoints.Text
        If CInt(txtPVAvailableThisTurn.Text) > CInt(txtDeploymentZonePV.Text) Then txtPVAvailableThisTurn.Text = txtDeploymentZonePV.Text

        Return True

    End Function

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        m_ActionCancelled = False

        If ValidateProperties() = True Then
            ' increase the deployed point value for this faction
            Dim fact As cmplib01.Faction
            fact = ptrCurrentGame.Faction_g.Item(ptrCurrentGame.selectedPlayer.FactionKey)
            fact.FactionDeployedPoints += ptrNewUnit.CurrentPointValue
            Me.Hide()
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        m_ActionCancelled = True
        Me.Hide()
    End Sub

    Private Function ValidateProperties() As Boolean
        ' make sure that an item has been selected
        If bunitSelected = False Then
            MessageBox.Show("You must select a unit type to deploy.", "Select Unit Type", MessageBoxButtons.OK)
            Return False
        End If

        ' validate point values ( the txtpvavailablethisturn.text is the greatest amount that can be deployed at this location)
        Try
            If CInt(txtPointValue.Text) > CInt(txtPVAvailableThisTurn.Text) Then
                MessageBox.Show("The point value for this unit is greater than the free points available. Reduce the point value or cancel the deployment.", "Invalid Point Value", MessageBoxButtons.OK)
                Return False
            End If
        Catch ex As Exception
            MessageBox.Show("You must enter a numerical point value.", "Invalid Point Value", MessageBoxButtons.OK)
            Return False
        End Try

        ' heres where it is actually set up
        Try
            'TODO: WATCH: I'm not sure if this will cause a weird error with deployed units (and it did)
            SelectedUnit.CurrentPointValue = CInt(txtPointValue.Text)
            SelectedUnit.InitialPointValue = CInt(txtPointValue.Text)
            SelectedUnit.Name = txtChitName.Text
            Return True
        Catch ex As Exception
            HandleException("frmDeployUnit", ex)
            Return False
        End Try
    End Function

#Region "Properites"
    Public Property ActionCancelled() As Boolean
        Get
            Return m_ActionCancelled
        End Get
        Set(ByVal Value As Boolean)
            m_ActionCancelled = Value
        End Set
    End Property
#End Region

    Private Sub btnElements_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnElements.Click
        Dim fEditEles As New frmElementManager(ptrCurrentGame, ptrNewUnit)
        fEditEles.ShowDialog()
        ShowElements()
        If chkUseElementsForPointValue.Checked = True Then
            CalculatePointValueFromElements()
        End If
    End Sub

    Private Sub ShowElements()
        Dim ele As Element

        lvwElements.Items.Clear()

        For Each ele In ptrNewUnit.ChitElements
            Dim listi As New ListViewItem(ele.Count)
            listi.SubItems.Add(ele.ElementTypeName)
            lvwElements.Items.Add(listi)
        Next

    End Sub

    Private Sub chkUseElementsForPointValue_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkUseElementsForPointValue.CheckedChanged
        If chkUseElementsForPointValue.Checked = True Then
            txtPointValue.ReadOnly = True
            CalculatePointValueFromElements()
        Else
            txtPointValue.ReadOnly = False
        End If
    End Sub

    Private Function CalculatePointValueFromElements()
        Dim ele As Element
        Dim eleType As ElementType
        Dim tPV As Integer

        Try
            For Each ele In ptrNewUnit.ChitElements
                tPV += ele.TotalCost
            Next
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

        txtPointValue.Text = tPV

    End Function

End Class
